package com.action;

import com.service.UserService;
import com.vo.ResponseBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * User: Qsxmj
 * Date: 2019/10/9 16:02
 * Content:
 *
 * @author qsxmji
 */
@RestController
@CrossOrigin("*")
@RequestMapping("/api/user")
public class UserAction {
    @Autowired
    private UserService userService;

    /**
     * @param id          用户id
     * @param oldPassword 原密码
     * @param newPassword 新密码
     * @return 首先验证数据库是否有该用户， 再进行修改
     */
    @RequestMapping("/updatePassword")
    public ResponseBean updatePassword(int id, String oldPassword, String newPassword) {
        int n = userService.checkPassword(id, oldPassword);
        if (n > 0) {
            userService.updatePassword(id, newPassword);
            return new ResponseBean(200, 0, "修改成功");
        }
        return new ResponseBean(500, 0, "修改失败");
    }


}
